package com.bawei.mall.user.factory;

import com.bawei.common.core.domain.R;
import com.bawei.common.core.utils.StringUtils;
import com.bawei.mall.user.domain.request.UserInformati;
import com.bawei.mall.user.remote.RemoteUserInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author DongZl
 * @description: 远程调用服务的熔断
 * @Date 2022-10-15 上午 08:42
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserInfo> {

    private final static Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserInfo create (Throwable cause) {
        log.error("用户服务 - 用户信息 - 远程调用异常", cause);
        return new RemoteUserInfo() {
            @Override
            public R<UserInformati> getUser(String username) {
                return R.fail(StringUtils.format("获取用户信息失败，错误信息:[{}]",cause.getMessage()));
            }
        };
    }
}
